package OSMS.action.Boss;

import java.io.IOException;

import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import OSMS.entity.*;
import OSMS.dao.*;

public class GoodsSearchServlet extends HttpServlet {

	private GoodsDao dao = new GoodsDao();
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		//获取goodslist.jsp传来的gname
		Object name = request.getParameter("gname");
		String gname = null;
		if(name!=null){
			gname=name.toString();
		}

		boolean flag = false ;
		try {
			//调用dao的方法通过商品名称查询商品信息
			List<Goods> goodsList = dao.searchGoodsByGname(gname);
			//将数据装入域对象中。
			request.setAttribute("goodsList", goodsList);
			//将查询结果跳转到seartchgoods.jsp页面中展示
			request.setCharacterEncoding("utf-8");
			request.getRequestDispatcher("../boss/index.jsp").forward(request, response);
		}catch(Exception e) {
			e.printStackTrace();
		}
		
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}
	
	
}
